package com.manning.readinglist.utils;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @Classname JdbcTemplateCondition
 * @Description TODO
 * @Date 2020/5/20 14:36
 * @Created by seed
 */
public class JdbcTemplateCondition implements Condition {
    /*
    使用方法：
    在类上添加注解：@Conditional(JdbcTemplateCondition.class)
    只有matches返回true时，才会创建Conditional注解所在的类
     */
    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        try {
            conditionContext.getClassLoader().loadClass("org.springframework.jdbc.core.JdbcTemplate");
            return true;
        }catch (Exception e){
            return false;
        }
    }
}
